PROJECTENGRAM

TESTING AND DEBUGGING

Testing and Debugging

Tags: #◇Conceptual #◇CCPROG1 #◇Debugging #◇Software Quality #◇M7


◇Overview

Testing is the process of evaluating a program to verify that it functions exactly as intended, while debugging is the process of finding and fixing the defects (bugs) discovered during testing or execution.

◇Key Definitions

Bug: An error, flaw, or fault in a computer program that produces an incorrect or unexpected result. Syntax Error: Mistakes in the source code grammar that prevent the code from compiling. Logic Error: The program runs but produces incorrect outputs because the underlying algorithm is flawed. Runtime Error: Errors that occur during the execution of a program (e.g., dividing by zero). Test Cases: Specific sets of inputs and expected outputs used to test a program.

◇Theoretical Framework

The Debugging Process

  1. Identify the Error: Notice that the program is not behaving as expected.
  2. Analyze the Cause: Understand why the error is occurring.
  3. Fix the Bug: Modify the code to resolve the issue.
  4. Re-test: Verify that the fix worked and did not introduce new bugs.

Testing Strategies Black-box Testing: Testing functionality without looking at the internal code structure. Focuses purely on inputs and expected outputs. White-box Testing: Testing internal structures, logic paths, and edge cases by reading the source code. Boundary/Edge Cases: Testing values at the extremes of allowed inputs (e.g., an empty string, 0, negative numbers).

[!tip] Best Practice
When debugging in C, a simple but effective technique is adding printf() statements at key points to track variable values and control flow. For complex issues, use a debugger like gdb to step through the code line by line.

◇Common Pitfalls

Changing code randomly in hopes of fixing a bug ("shotgun debugging") instead of tracing the logic. Testing only the "happy path" (normal inputs) and ignoring edge cases. Failing to properly read compiler error messages, which often point directly to the source of syntax errors.

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

Which type of error occurs when a C program compiles without warnings or errors, runs to completion, but produces an incorrect calculation result (such as using + instead of *)?

Q2

When designing test cases for a function that accepts a student score in the valid range [0, 100], which set of inputs best represents Boundary Value Analysis?

Q3

What is the difference between Black-Box Testing and White-Box Testing?

Q4

Which of the following causes a Linker Error rather than a Compile-Time Syntax Error in C?

Q5

What is a "driver" in the context of unit testing modular C programs?

Testing and Debugging | PROJECT ENGRAM